
<template>
<div>
	<h1>index aa</h1>
	<p>{{$store.state.user.userName}}{{$store.state.user.token}} 
		<button v-on:click="exit">退出</button>
	</p>
	<button v-on:click="settoken">token set</button>
	<button v-on:click="set_storage">storage token set </button>
	store title <input type="text" v-model="store_title"><br>
	<form v-bind:action="url" method="post" target="if1" enctype="multipart/form-data">
            <input  type="file" name="uploadFile">
            <button>submit</button>
    </form>
	<iframe name="if1" height="100px"></iframe>
	<input type="file"  id="file1">
    <button v-on:click="postfile">formdata 单文件上传</button>
    <button v-on:click="getlist">list</button>
</div>
</template>
<script>
export default {
	data(){
		return {
			url:'/public/file/upload?access_token='+this.$store.state.user.token
		}
	},methods:{
		exit(){
			this.storage.removeItem('user');
			this.$router.go('/login')
		},postfile(){
			var d=new FormData();
            var file=document.querySelector('#file1').files;
            d.append('uploadFile',file[0])
            this.$ajax.post('/public/file/upload',d).then(function(res){
                if(res.data.errorCode==0){
					alert(JSON.stringify(res.data.data))
				}
            })
		},settoken(){
			var user=this.$store.state.user;
			user.token='fdsafdsa';
			this.$store.commit('SET_ONLINE_USER',user);
		},set_storage(){
			var u=JSON.parse(this.storage.getItem('user'));
			u.token='fdasfdas';
			this.storage.setItem('user',JSON.stringify(u))
		},getlist(){
			this.$ajax.post('/goverment/med/list',{pageSize:20,page:1}).then((res)=>{
				console.log(res.data)
			})
		}
	},created(){
		this.$ajax.post('/token/getPublicKey').then(function(res){
			console.log(res.data);
		})
	},
	computed:{
		store_title:{
			get(){
				return this.$store.state.title
			},
			set (value){
				this.$store.commit('SET_TITLE',value)
			}
		}
	}
} 
</script>